<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>我的账号</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no" />
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/common.css" />
    <link rel="stylesheet" href="../css/y_index.css" />
</head>

<body>
    <div class="">
        <form action="" enctype="multipart/form-data" method="post" name="form" id="form">
            <label class="flex_sb plr30 ptb30 bw">
                <input type="file" name="files" hidden id="hd_img" />
                <span class="col3 font15">编辑头像</span><em class="flex_a"><img class="mr20 hd_img"  id="headimg"/><img src="../img/arrow_right.png" class="arrow_r"/></em>
            </label>
        </form>
        <div class="flex_a plr30 font15 mt20 bw bdb" id="nickname">
            <span class="col3">昵称</span><em class="flex_a"><input type="text" placeholder="请输入昵称" class="ml20 nickname font15 col9 h100 flex1"></em>
        </div>
        <div class="flex_sb ptb30 plr30 font15  bw bdb" id="phone">
            <span class="col3">账号</span><em class="flex_a"><i class="col9  phone">15812874182</i></em>
        </div>
        <a href="./zy_gaiPassword.html" class="flex_sb ptb30 plr30 font15 bw bdb">
        <span class="col3">修改密码</span><em class="flex_a"><img src="../img/arrow_right.png" class="arrow_r"/></em>
    </a>
        <a href="./zy_address.html" class="flex_sb ptb30 plr30 font15 bw">
        <span class="col3">地址管理</span><em class="flex_a"><img src="../img/arrow_right.png" class="arrow_r"/></em>
    </a>
        <div class="main_btn" style="margin-top: .6rem">保存</div>
    </div>
</body>

</html>
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script type="text/javascript" src="../js/jquery.form.js"></script>
<script>
var onoff = 0;
addEventback();
userInfo();

function userInfo() {
    dlctipbox.loading('载入中...');
    dlc_request('/api/apiAgent/queryAgentInfo', { 'id': getLocalData('fd_id') }, function(res) {
        dlctipbox.clear();
        console.log(res);
        if (res.code == 1) {
            var res = res.data[0];
            $('#headimg').attr('src', (res.headImgUrl ? res.headImgUrl : '../img/default.png'));
            if (res.name) {
                $('.nickname').val(res.name);
            }
            $('.phone').text(res.phone);
        } else {
            dlctipbox.show(res.msg);
        }
    });
}


//保存
$('.confirm').click(function() {
    var nickname = $('.nickname').val();
    if (isNull(nickname)) {
        dlctipbox.show('请输入昵称');
    } else {
        if (onoff) return false;
        onoff = 1;
        dlctipbox.loading('请稍后');
        dlc_request('/api/apiAgent/updataHeadImgOrInfo', { 'id': getLocalData('fd_id'), 'name': nickname }, function(res) {
            console.log(res);
            dlctipbox.clear();
            if (res.code == 1) {
                dlctipbox.show('保存成功');
                $('.nickname').val('');
                userInfo();
            } else {
                onoff = 0;
                dlctipbox.show(res.msg);
            }
        });
    }
});

$('#hd_img').on('change', function() {
    $('#form').ajaxSubmit({
        url: dlcUrl() + '/api/upload',
        type: 'POST',
        dataType: 'json',
        beforeSubmit: function() {
            dlctipbox.loading('上传中..');
        },
        success: function(res) {
            console.log(res);
            if (res.code == 1) {
                dlc_request('/api/apiAgent/updataHeadImgOrInfo', { 'id': getLocalData('fd_id'), 'imgUrl': res.data.imgPath[0] }, function(res) {
                    console.log(res);
                    dlctipbox.clear();
                    if (res.code == 1) {
                        userInfo();
                        dlctipbox.show('修改成功');
                    } else {
                        dlctipbox.show(res.msg);
                    }
                });
            } else {
                dlctipbox.show(res.msg);
            }
        },
        error: function(err) {
            console.log(err);
        }
    });
});
</script>